package com.zking.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice // AOP（advice/advisor）增强处理器
public class MyControllerAdvice {
    @ExceptionHandler(Exception.class) // 注解表示可以处理【指定】异常
    public String handler1() {
        System.out.println("~~~ 未知异常！Exception");
        return "error";
    }
    
    @ExceptionHandler({NullPointerException.class, IndexOutOfBoundsException.class})
    public String handler2(Exception e) {
        System.out.println("~~~ 出错了！NullPointerException, IndexOutOfBoundsException");
        return "error";
    }
    
    @ExceptionHandler({NumberFormatException.class}) // 具体的异常处理
    public String handler3(NumberFormatException e) {
        System.out.println("~~~ 出错了：" + e.getMessage());
        return "error";
    }
}
